package interview;

public class interview_17_11 {
    public int findClosest(String[] words, String word1, String word2) {
        int index1=-1;
        int index2=-1;
        int min=words.length;
        for(int i=0;i<words.length;++i){
            if(words[i].equals(word1)){
                index1=i;
                if(index2!=-1){
                    min=Math.min(min,Math.abs(index1-index2));
                }
            }
            if(words[i].equals(word2)){
                index2=i;
                if(index1!=-1){
                    min=Math.min(min,Math.abs(index1-index2));
                }
            }
        }
        return min;
    }
}
